package org.xg.study.servlet;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * @author CMG
 * @version 1.0
 * @description
 * @cLassName FilterDemo
 * @date 2021/9/24 15:36
 **/
@WebFilter(dispatcherTypes = {
        DispatcherType.REQUEST,
        DispatcherType.FORWARD,
        DispatcherType.INCLUDE,
        DispatcherType.ERROR
},
        urlPatterns = {"/filterServlet"}
)
public class FilterDemo implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        servletResponse.setContentType("text/html;charset=UTF-8");
        servletResponse.getWriter().write("<h1>Hello MyFilter</h1>");
    }

    @Override
    public void destroy() {

    }
}
